1 顺序存储的二叉树
2 顺序存储的二叉树的遍历 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 package demo6;public class ArrayBinaryTree { int [] data; public ArrayBinaryTree (int [] data) { this .data=data; } public void frontShow () { frontShow(0 ); } public void frontShow (int index) { if (data==null ||data.length==0 ) { return ; } System.out.println(data[index]); if (2 *index+1 <data.length) { frontShow(2 *index+1 ); } if (2 *index+2 <data.length) { frontShow(2 *index+2 ); } } }
Test 1 2 3 4 5 6 7 8 9 10 11 public class TestArrayBinaryTree { public static void main (String[] args) { int [] data = new int [] {1 ,2 ,3 ,4 ,5 ,6 ,7 }; ArrayBinaryTree tree = new ArrayBinaryTree(data); tree.frontShow(); } }
Author:
John Doe
Permalink:
http://yoursite.com/2019/09/28/数据结构算法/数据结构与算法 总结笔记/4 树/顺序存储的二叉树/
License:
Copyright (c) 2019 CC-BY-NC-4.0 LICENSE
Slogan:
Do you believe in DESTINY?